﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xproject.Framework.Core;
using Xproject.Framework.Core.DataContext;
using Xproject.Framework.Core.Repositories;
using Model.Util;
using Repository.Util;
using Xproject.Util;
namespace Services.Util
{
   public  class IdentityServices:Service
    {
        IRepositoryAsync<Identity> m_IdentityRepository;

        public IdentityServices(IDataContextAsync dataContext) : base(dataContext)
        {
            m_IdentityRepository = m_UnitOfWork.RepositoryAsync<Identity>();
        }
        /// <summary>
        /// 增一个Identity 这样能取到这个userId的userCode
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool InsertAnUserId(string userId)
        {
            Identity identity = new Identity();
            identity.ProjectID = userId;
            identity.CreateTime = DateTime.Now;
            identity.EntityState = EntityState.Added;
            m_IdentityRepository.Insert(identity);
            int usercode = identity.ID;
            return m_UnitOfWork.SaveChanges() == 1;
        }

        public Identity GetByUserId(string userId)
        {
            return m_IdentityRepository.GetByUserId(userId);
        }
    }

}
